<!--
  企业端-人才夹-收藏列表
 -->
<template>
  <div class="app-container">
    <el-form
      ref="rightQueryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="性别" prop="sex">
        <el-select
          v-model="queryParams.sex"
          placeholder="请选择性别"
          clearable
          size="small"
        >
          <el-option label="不限" value="" />
          <el-option label="男" value="男" />
          <el-option label="女" value="女" />
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.startDate"
          type="number"
          style="width: 100px"
          placeholder="岁"
        />
        至
        <el-input
          v-model="queryParams.endDate"
          type="number"
          style="width: 100px"
          placeholder="岁"
        />
      </el-form-item>
      <el-form-item label="居住地" prop="liveCity">
        <el-cascader
          v-model="queryParams.liveCity"
          :show-all-levels="false"
          :options="provinceAndCityData"
          :props="{ value: 'label' }"
          placeholder="请选择城市"
        />
      </el-form-item>
      <el-form-item label-width="80px" label="学生名称" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="学生名称"
          style="width:120px"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="求职意向" prop="internshipDesire">
        <el-input
          v-model="queryParams.internshipDesire"
          placeholder="支持模糊匹配"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="求职状态" prop="jobStatus" label-width="100px">
        <el-select v-model="queryParams.jobStatus">
          <el-option label="不限" :value="null" />
          <el-option label="正在实习" value="正在实习" />
          <el-option label="暂无实习" value="暂无实习" />
        </el-select>
      </el-form-item>
      <el-form-item
        label-width="120px"
        label="学校/学历/专业"
        prop="educationalExperience"
      >
        <el-input
          v-model="queryParams.educationalExperience"
          placeholder="支持模糊匹配"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >搜索</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" type="index" />
      <el-table-column label="姓名" align="center" prop="studentName" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="学历" align="center" prop="educationalBackground" />
      <el-table-column label="学校" align="center" prop="schoolName" />
      <el-table-column label="所学专业" align="center" prop="major" />
      <el-table-column label="居住地" align="center" prop="liveCity" />
      <el-table-column label="最新备注" align="center" prop="remarks">
        <template slot-scope="scope">
          {{ scope.row.remarks || '--' }}
        </template>
      </el-table-column>
      <el-table-column label="求职状态" align="center" prop="jobStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.jobStatus">{{ scope.row.jobStatus }}/</span>
          <span>{{ scope.row.inJobTime || '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 查看简历详情 -->
    <el-drawer
      title="学生详情"
      size="90%"
      :visible.sync="ResumeReviewDialog"
      direction="rtl"
    >
      <el-tabs v-if="ResumeReviewDialog" v-model="activeName" type="card">
        <el-tab-pane label="学生简历" name="1">
          <ResumeReview ref="ResumeReview" :is-data-list="true" :is-collection="true" @saveCollectFun="saveCollectFun" />
        </el-tab-pane>
        <el-tab-pane label="备注列表" name="2">
          <RemarksList v-if="activeName=='2'" relation-type="2" :relation-id="relationId" />
        </el-tab-pane>
      </el-tabs>

    </el-drawer>
  </div>
</template>

<script>
import { getEnterpriseStudentPage } from '@/api/company-admin-api/hireManage/index.js'
import { getStudentResume } from '@/api/school-admin-api/userManage/student/index.js'
import { resumeStatus, provinceAndCityData } from '@/utils/frontDataDict.js'
import ResumeReview from '@/components/resumeReview/index.vue'
import RemarksList from '@/components/remarksList/index.vue'
import { getAge } from '@/utils/utils'
import moment from 'moment'
export default {
  name: 'JobObjective',
  components: {
    ResumeReview,
    RemarksList
  },
  data() {
    return {
      moment: moment,
      provinceAndCityData,
      resumeStatus: resumeStatus, // 职位上下架状态
      // 遮罩层
      loading: true,
      // 简历列表-总条数
      total: 0,
      // 简历列表列表
      list: [],
      ResumeReviewDialog: false,
      relationId: null,
      activeName: '1',
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        educationalExperience: '', // 教育经历模糊搜索
        sex: '', // 性别
        startDate: '', // 年龄起始日期
        endDate: '', // 年龄结束日期
        liveCity: [], // 居住地
        studentName: '', // 学校/学历/专业 模糊匹配
        internshipDesire: '', // 求职意向 模糊匹配
        jobStatus: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getAgeStr(date) {
      return getAge(date)
    },
    saveCollectFun() {
      this.getList()
    },
    // 未发布列表数据
    getList() {
      this.loading = true
      // 处理查询参数
      const params = JSON.parse(JSON.stringify(this.queryParams))
      if (this.queryParams.startDate) {
        const now = new Date().getTime()
        params.endDate = moment(now - 1000 * 60 * 60 * 24 * 365 * this.queryParams.startDate).format('yyyy-MM-DD')
      }
      if (this.queryParams.endDate) {
        const now = new Date().getTime()
        params.startDate = moment(now - 1000 * 60 * 60 * 24 * 365 * this.queryParams.endDate).format('yyyy-MM-DD')
      }
      if (Array.isArray(params.liveCity) && params.liveCity.length === 2) {
        params.liveCity = params.liveCity[1]
      } else {
        delete params.liveCity
      }
      // 执行查询
      params.collectStatus = '1'
      getEnterpriseStudentPage(params).then((response) => {
        let list = []
        if (response.data && response.data.list) {
          list = response.data.list.map(item => {
            if (
              Array.isArray(item.educationalList) &&
                item.educationalList.length
            ) {
              const educate = ['大专', '本科', '硕士', '博士']
              educate.map((iten) => {
                const matchEducate = item.educationalList.find(
                  (single) => single.educationalBackground.indexOf(iten) > -1
                )
                if (matchEducate) {
                  item.schoolName = matchEducate.schoolName // 学校名称
                  item.major = matchEducate.major // 专业
                  item.educationalBackground = iten
                  // item.education = iten // 学历
                }
              })
            } else {
              item.schoolName = '--' // 学校名称
              item.major = '--' // 专业
              item.educationalBackground = '--' // 学历
            }
            return item
          })
        }
        this.list = list
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    // 重制搜索条件
    resetQuery() {
      this.resetForm('rightQueryForm')
      this.queryParams.startDate = ''
      this.queryParams.endDate = ''
      this.handleQuery()
    },
    /** 打开应聘详情 */
    handleCheck(row) {
      this.relationId = row.id
      getStudentResume({ studentId: row.id }).then((res) => {
        if (res.code === 0 && res.data && res.data.studentCurriculumVitaeRespVOList) {
          this.ResumeReviewDialog = true
          setTimeout(() => {
            res.data.ages = row.age
            res.data.relationType = '5'
            res.data.collectStatus = row.collectStatus
            this.$refs.ResumeReview.open(res.data.studentCurriculumVitaeRespVOList, res.data)
          })
        }
      })
    }
  }
}
</script>

